layui.use(['form','tree','laydate','element','table','laytpl','layer','jquery'],function(){
    var form = layui.form,
        element = layui.element;
    $ = layui.$;
    var layer = parent.layer === undefined ? layui.layer : top.layer;
    var table = layui.table;
    var laytpl = layui.laytpl;
    var layedit = layui.layedit;
    var laydate = layui.laydate;

    //饼状线图
    //采集设备分类饼状图
    var pieChart1 = echarts.init(document.getElementById('pie-chart1'));
    var pieoption1 = {
        title : {
            text: '采集设备数量分布',
            subtext: ' ',
            x:'center'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: [ "环境采集设备-ZK03", "监控设备" ]
        },
        series : [
            {
                name: '采集设备数量',
                type: 'pie',
                radius : '55%',
                center: ['50%', '60%'],
                data:[
                    { value: 1, name: "环境采集设备-ZK03" },
                    { value: 1, name: "监控设备" },
                ],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    getPieoPtionData_1();
    function getPieoPtionData_1() {
        $.get("/equipment/type/list",function (data) {
            //获取分类数据
            var legend = {
                orient: 'vertical',
                left: 'left',
                data: []
            };
            var series =  [
                {
                    name: '采集设备数量',
                    type: 'pie',
                    radius : '55%',
                    center: ['50%', '60%'],
                    data:[],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ];
            $.each(data.data,function (i, ele) {
                legend.data.push(ele.name);
                var obj = {value:0, name: ele.name};
                //获取分类的设备数据
                $.ajax({
                    url : "/equipment/query?typeId=" + ele.id,
                    async:false,
                    success: function (data) {
                        if (data.count > 0) {
                            obj.value = data.count;
                            series[0].data.push(obj);
                        }
                    }
                });
            });
            pieoption1.legend = legend;
            pieoption1.series = series;
            pieChart1.setOption(pieoption1);
        });
    }

});
